//
//  UIView+XLLevelInView.m
//  digital_robot_demo
//
//  Created by xskj on 2024/9/26.
//

#import "UIView+XLLevelInView.h"

@implementation UIView (XLLevelInView)



// 要获取视图在指定视图上的层级
+ (NSInteger)viewLevelInView:(UIView *)view{
    UIView *currentView = view;
    NSInteger level = 0;
    
    while (currentView.superview != nil) {
        currentView = currentView.superview;
        level++;
    }
    
    return level;
}



+ (NSInteger)indexOfView:(UIView *)targetView inSuperView:(UIView *)superView {
    for (UIView *subview in superView.subviews) {
        if (subview == targetView) {
            // 找到目标视图，返回其在子视图数组中的索引
            return [superView.subviews indexOfObject:subview];
        }
    }
    // 没有找到目标视图
    return -1;
}

@end
